{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lb5yiH5h8x3h"
      },
      "source": [
        "##### Copyright 2025 Google LLC."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "906e07f6e562"
      },
      "outputs": [],
      "source": [
        "# @title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "# https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1YXR7Yn480fU"
      },
      "source": [
        "# Search tool with Gemini 2+"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CeJyB7rG82ph"
      },
      "source": [
        "<a target=\"_blank\" href=\"https://colab.research.google.com/github/google-gemini/cookbook/blob/main/examples/Search_grounding_for_research_report.ipynb\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" height=30/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "___eV40o8399"
      },
      "source": [
        "In this tutorial you are going to leverage the latest [search tool](https://ai.google.dev/gemini-api/docs/google-search) of the Gemini model to write a company report. Note that the search tool is a paid ony feature and this tutorial does not work with a free tier API key.\n",
        "\n",
        "You may be asking, why does one need to use the search tool for this purpose? Well, as you may be aware, today's business world evolves very fast and LLMs generally are not trained frequently enough to capture the latest updates. Luckily Google search comes to the rescue. Google search is built to provide accurate and nearly realtime information and can help us fulfill this task perfectly.\n",
        "\n",
        "Note that while Gemini 1.5 models offered the [search grounding](https://ai.google.dev/gemini-api/docs/grounding) feature which may also help you achieve similar results (see [a previous notebook](https://github.com/google-gemini/cookbook/blob/gemini-1.5-archive/examples/Search_grounding_for_research_report.ipynb) using search grounding), the new search tool in Gemini 2.0 and later models is much more powerful and easier to use, and should be prioritized over search grounding. It is also possible to use multiple tools together (for example, search tool and function calling)."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Mfk6YY3G5kqp"
      },
      "source": [
        "## Setup"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "d5027929de8f"
      },
      "source": [
        "### Install SDK\n",
        "\n",
        "The new **[Google Gen AI SDK](https://ai.google.dev/gemini-api/docs/sdks)** provides programmatic access to the Gemini models using both the [Google AI for Developers](https://ai.google.dev/gemini-api/docs) and [Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/overview) APIs. With a few exceptions, code that runs on one platform will run on both. This means that you can prototype an application using the Developer API and then migrate the application to Vertex AI without rewriting your code.\n",
        "\n",
        "More details about this new SDK on the [documentation](https://ai.google.dev/gemini-api/docs/sdks) or in the [Getting started](../quickstarts/Get_started.ipynb) notebook."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "46zEFO2a9FFd"
      },
      "outputs": [],
      "source": [
        "%pip install -U -q google-genai"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CTIfnvCn9HvH"
      },
      "source": [
        "### Setup your API key\n",
        "\n",
        "To run the following cell, your API key must be stored it in a Colab Secret named `GOOGLE_API_KEY`. If you don't already have an API key, or you're not sure how to create a Colab Secret, see [Authentication ![image](https://storage.googleapis.com/generativeai-downloads/images/colab_icon16.png)](../quickstarts/Authentication.ipynb) for an example."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "A1pkoyZb9Jm3"
      },
      "outputs": [],
      "source": [
        "from google.colab import userdata\n",
        "\n",
        "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "QclzsisW0nTK"
      },
      "source": [
        "### Import the libraries"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "cXNAAIqOuXlO"
      },
      "outputs": [],
      "source": [
        "from google import genai\n",
        "from google.genai.types import GenerateContentConfig, Tool\n",
        "from IPython.display import display, HTML, Markdown\n",
        "import io\n",
        "import json\n",
        "import re"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3Hx_Gw9i0Yuv"
      },
      "source": [
        "### Initialize SDK client\n",
        "\n",
        "With the new SDK you now only need to initialize a client with you API key (or OAuth if using [Vertex AI](https://cloud.google.com/vertex-ai)). The model is now set in each call."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "HghvVpbU0Uap"
      },
      "outputs": [],
      "source": [
        "client = genai.Client(api_key=GOOGLE_API_KEY)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "QOov6dpG99rY"
      },
      "source": [
        "### Select a model\n",
        "\n",
        "Search tool is a new feature in the Gemini models that automatically retrieves accurate and grounded artifacts from the web for developers to further process. Unlike the search grounding in the Gemini 1.5 models, you do not need to set the dynamic retrieval threshold.\n",
        "\n",
        "For more information about all Gemini models, check the [documentation](https://ai.google.dev/gemini-api/docs/models/gemini) for extended information on each of them.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "27Fikag0xSaB"
      },
      "outputs": [],
      "source": [
        "MODEL_ID = \"gemini-2.5-flash\" # @param [\"gemini-2.5-flash-lite\",\"gemini-2.5-flash\",\"gemini-2.5-pro\",\"gemini-3-pro-preview\"] {\"allow-input\":true, isTemplate: true}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F9lFY3h6unY2"
      },
      "source": [
        "## Write the report with Gemini"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "j562CvvWvASd"
      },
      "source": [
        "### Select a target company to research\n",
        "\n",
        "Next you will use Alphabet as an example research target."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "7UQxJr7UvEhl"
      },
      "outputs": [],
      "source": [
        "COMPANY = 'Alphabet' # @param {type:\"string\"}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HALOE8He78H1"
      },
      "source": [
        "### Have Gemini plan for the task and write the report\n",
        "\n",
        "The newest Gemini models are a huge step up from previous models since they can reason, plan, search and write in one go. In this case, you will only give Gemini a prompt to do all of these and the model will finish your task seamlessly. You will also using output streaming, which streams the response as it is being generated, and the model will return chunks of the response as soon as they are generated. If you would like the SDK to return a response after the model completes the entire generation process,  you can use the non-streaming approach as well.\n",
        "\n",
        "Note that you must enable Google Search Suggestions, which help users find search results corresponding to a grounded response, and [display the search queries](https://ai.google.dev/gemini-api/docs/grounding/search-suggestions#display-requirements) that are included in the grounded response's metadata. You can find [more details](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) about this requirement."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "IAl2UGtw0LPG"
      },
      "outputs": [
        {
          "data": {
            "text/markdown": [
              "Okay"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              ", I will research Alphabet and create a company report. Here's my plan"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              ":\n",
              "\n",
              "1.  **Company Overview:** I'll start by gathering basic"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " information about Alphabet, such as its founding date, headquarters, and what it does.\n",
              "2.  **Business Segments:** I'll identify the different"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " business segments that Alphabet operates in (e.g., Google Services, Google Cloud, Other Bets).\n",
              "3.  **Recent News and Developments:** I'"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "ll look for recent news articles and press releases to understand any significant updates, product launches, or strategic shifts.\n",
              "4.  **Financial Performance:** I'll try to find information about Alphabet's recent financial performance, including revenue,"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " profit, and key metrics.\n",
              "5.  **Stock Information:** I'll check the current stock price and any recent stock-related news.\n",
              "6.  **Key People:** I'll identify key executives and board members."
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "\n",
              "7.  **Competitive Landscape:** I'll briefly touch on the competitive landscape and Alphabet's main competitors.\n",
              "\n",
              "Now, let's start with the searches.\n",
              "\n"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "Okay"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              ", I've gathered a lot of information about Alphabet. Here's a"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " company report:\n",
              "\n",
              "---\n",
              "**Company Report: Alphabet Inc.**\n",
              "\n",
              "**Overview"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              ":**\n",
              "\n",
              "Alphabet Inc. is a multinational technology conglomerate holding company headquartered in Mountain View, California. It was created through a restructuring of Google on October 2,"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " 2015, becoming the parent company of Google and several former Google subsidiaries. Alphabet is the world's second-largest technology company by revenue,"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " after Apple, and one of the world's most valuable companies. It is considered one of the Big Five American information technology companies, alongside Amazon, Apple, Meta, and Microsoft.\n",
              "\n",
              "**Founding and Restructuring:**\n",
              "\n",
              "While Google"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " was founded in 1998 by Larry Page and Sergey Brin, Alphabet Inc. was formed on October 2, 2015, as a restructuring to make the core Google business \"cleaner and more accountable\""
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " while allowing greater autonomy to other ventures. In December 2019, Larry Page and Sergey Brin stepped down from their executive roles, and Sundar Pichai, who was already CEO of Google, became CEO of both Google and Alphabet. Page and Brin remain employees, board members, and controlling shareholders."
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "\n",
              "\n",
              "**Business Segments:**\n",
              "\n",
              "Alphabet operates through three main reportable segments:\n",
              "\n",
              "*   **Google Services:** This segment includes Google's core internet products such as ads, Android, Chrome, hardware, Google Cloud, Google Maps, Google Play, Search, and YouTube. This is the most profitable segment, with"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " revenue primarily generated from advertising on Google Search and YouTube, as well as subscriptions and smartphone sales.\n",
              "*   **Google Cloud:** This segment provides cloud services for businesses, including office software and computing platforms. Google Cloud's quarterly revenues have recently surpassed $10 billion, and it is showing strong growth.\n",
              "*"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "   **Other Bets:** This segment includes various cutting-edge technology innovation ventures at different stages of development, such as Access, Calico, CapitalG, GV, Verily, Waymo, and X. This segment often posts operating losses.\n",
              "\n",
              "**Recent News and Developments:**\n",
              "\n",
              "*   Alphabet's stock recently"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " reached an all-time high after unveiling its latest AI model, Gemini 2.0, and showcasing a new quantum computing chip called Willow.\n",
              "*   Google has launched Gemini, formerly known as Bard, an AI chatbot that supports over 40 languages.\n",
              "*   Alphabet's Q3 20"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "24 results showed a 15% increase in consolidated revenue year-over-year, reaching $88.3 billion. Google Services revenue increased by 13% to $76.5 billion.\n",
              "*   Google Cloud's revenue exceeded $10 billion in a recent quarter, with over"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " $1 billion in operating profit.\n",
              "*   Alphabet announced a cash dividend of $0.20 per share in July 2024.\n",
              "\n",
              "**Financial Performance:**\n",
              "\n",
              "*   In Q3 2024, Alphabet's consolidated revenue was $88.3 billion, a 1"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "5% increase year-over-year.\n",
              "*   Net income for Q3 2024 was $26.3 billion, compared to $19.7 billion a year ago.\n",
              "*   For the nine months ended September 30, 2024, sales were $"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "253.5 billion, compared to $221.1 billion a year ago.\n",
              "*   Google Cloud's revenue has surpassed $10 billion in a recent quarter.\n",
              "*   Alphabet's revenue is primarily driven by Google Services, particularly advertising.\n",
              "\n",
              "**Stock Information:**\n",
              "\n",
              "*   "
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "Alphabet has two classes of stock: GOOG (Class C shares without voting rights) and GOOGL (Class A common stock).\n",
              "*   As of today, December 17, 2024, the price of GOOG is around $198.16, and it has increased"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " by 4.31% in the past 24 hours.\n",
              "*   The stock reached an all-time high on December 10, 2024.\n",
              "*   Analysts' price targets for GOOG range from $185 to $240.\n",
              "\n",
              "**Key People"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              ":**\n",
              "\n",
              "*   **CEO:** Sundar Pichai\n",
              "*   **Co-Founders:** Larry Page and Sergey Brin (remain board members and controlling shareholders)\n",
              "*   **Chief Financial Officer:** Anat Ashkenazi\n",
              "*   **Other Key Executives:** Philipp Schindler (Chief Business Officer, Google), Prabhakar"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              " Raghavan (Chief Technologist, Google), Ruth M. Porat (President and Chief Investment Officer; CFO)\n",
              "\n",
              "**Competitive Landscape:**\n",
              "\n",
              "Alphabet's main competitors include:\n",
              "\n",
              "*   **Other Big Tech Companies:** Apple, Microsoft, Meta, Amazon, IBM\n",
              "*   **Software Companies:** SAP, Pal"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "antir Technologies, Shopify, AppLovin, Infosys, CrowdStrike, Atlassian, Trade Desk, NetEase, Snowflake\n",
              "*   **Other Competitors:** ByteDance, Zoom, Salesforce, Tencent, Adobe\n",
              "\n",
              "**Additional Information:**\n",
              "\n",
              "*   Alphabet's headquarters is located at 160"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              "0 Amphitheatre Parkway in Mountain View, California, also known as the Googleplex.\n",
              "*   Alphabet has a global presence with employees across six continents.\n",
              "*   Alphabet is involved in investing in infrastructure, data management, analytics, and artificial intelligence (AI).\n",
              "\n",
              "This report provides a comprehensive overview of Alphabet Inc"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/markdown": [
              ". as of December 17, 2024.\n",
              "---\n"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/html": [
              "<style>\n",
              ".container {\n",
              "  align-items: center;\n",
              "  border-radius: 8px;\n",
              "  display: flex;\n",
              "  font-family: Google Sans, Roboto, sans-serif;\n",
              "  font-size: 14px;\n",
              "  line-height: 20px;\n",
              "  padding: 8px 12px;\n",
              "}\n",
              ".chip {\n",
              "  display: inline-block;\n",
              "  border: solid 1px;\n",
              "  border-radius: 16px;\n",
              "  min-width: 14px;\n",
              "  padding: 5px 16px;\n",
              "  text-align: center;\n",
              "  user-select: none;\n",
              "  margin: 0 8px;\n",
              "  -webkit-tap-highlight-color: transparent;\n",
              "}\n",
              ".carousel {\n",
              "  overflow: auto;\n",
              "  scrollbar-width: none;\n",
              "  white-space: nowrap;\n",
              "  margin-right: -12px;\n",
              "}\n",
              ".headline {\n",
              "  display: flex;\n",
              "  margin-right: 4px;\n",
              "}\n",
              ".gradient-container {\n",
              "  position: relative;\n",
              "}\n",
              ".gradient {\n",
              "  position: absolute;\n",
              "  transform: translate(3px, -9px);\n",
              "  height: 36px;\n",
              "  width: 9px;\n",
              "}\n",
              "@media (prefers-color-scheme: light) {\n",
              "  .container {\n",
              "    background-color: #fafafa;\n",
              "    box-shadow: 0 0 0 1px #0000000f;\n",
              "  }\n",
              "  .headline-label {\n",
              "    color: #1f1f1f;\n",
              "  }\n",
              "  .chip {\n",
              "    background-color: #ffffff;\n",
              "    border-color: #d2d2d2;\n",
              "    color: #5e5e5e;\n",
              "    text-decoration: none;\n",
              "  }\n",
              "  .chip:hover {\n",
              "    background-color: #f2f2f2;\n",
              "  }\n",
              "  .chip:focus {\n",
              "    background-color: #f2f2f2;\n",
              "  }\n",
              "  .chip:active {\n",
              "    background-color: #d8d8d8;\n",
              "    border-color: #b6b6b6;\n",
              "  }\n",
              "  .logo-dark {\n",
              "    display: none;\n",
              "  }\n",
              "  .gradient {\n",
              "    background: linear-gradient(90deg, #fafafa 15%, #fafafa00 100%);\n",
              "  }\n",
              "}\n",
              "@media (prefers-color-scheme: dark) {\n",
              "  .container {\n",
              "    background-color: #1f1f1f;\n",
              "    box-shadow: 0 0 0 1px #ffffff26;\n",
              "  }\n",
              "  .headline-label {\n",
              "    color: #fff;\n",
              "  }\n",
              "  .chip {\n",
              "    background-color: #2c2c2c;\n",
              "    border-color: #3c4043;\n",
              "    color: #fff;\n",
              "    text-decoration: none;\n",
              "  }\n",
              "  .chip:hover {\n",
              "    background-color: #353536;\n",
              "  }\n",
              "  .chip:focus {\n",
              "    background-color: #353536;\n",
              "  }\n",
              "  .chip:active {\n",
              "    background-color: #464849;\n",
              "    border-color: #53575b;\n",
              "  }\n",
              "  .logo-light {\n",
              "    display: none;\n",
              "  }\n",
              "  .gradient {\n",
              "    background: linear-gradient(90deg, #1f1f1f 15%, #1f1f1f00 100%);\n",
              "  }\n",
              "}\n",
              "</style>\n",
              "<div class=\"container\">\n",
              "  <div class=\"headline\">\n",
              "    <svg class=\"logo-light\" width=\"18\" height=\"18\" viewBox=\"9 9 35 35\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n",
              "      <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M42.8622 27.0064C42.8622 25.7839 42.7525 24.6084 42.5487 23.4799H26.3109V30.1568H35.5897C35.1821 32.3041 33.9596 34.1222 32.1258 35.3448V39.6864H37.7213C40.9814 36.677 42.8622 32.2571 42.8622 27.0064V27.0064Z\" fill=\"#4285F4\"/>\n",
              "      <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M26.3109 43.8555C30.9659 43.8555 34.8687 42.3195 37.7213 39.6863L32.1258 35.3447C30.5898 36.3792 28.6306 37.0061 26.3109 37.0061C21.8282 37.0061 18.0195 33.9811 16.6559 29.906H10.9194V34.3573C13.7563 39.9841 19.5712 43.8555 26.3109 43.8555V43.8555Z\" fill=\"#34A853\"/>\n",
              "      <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M16.6559 29.8904C16.3111 28.8559 16.1074 27.7588 16.1074 26.6146C16.1074 25.4704 16.3111 24.3733 16.6559 23.3388V18.8875H10.9194C9.74388 21.2072 9.06992 23.8247 9.06992 26.6146C9.06992 29.4045 9.74388 32.022 10.9194 34.3417L15.3864 30.8621L16.6559 29.8904V29.8904Z\" fill=\"#FBBC05\"/>\n",
              "      <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M26.3109 16.2386C28.85 16.2386 31.107 17.1164 32.9095 18.8091L37.8466 13.8719C34.853 11.082 30.9659 9.3736 26.3109 9.3736C19.5712 9.3736 13.7563 13.245 10.9194 18.8875L16.6559 23.3388C18.0195 19.2636 21.8282 16.2386 26.3109 16.2386V16.2386Z\" fill=\"#EA4335\"/>\n",
              "    </svg>\n",
              "    <svg class=\"logo-dark\" width=\"18\" height=\"18\" viewBox=\"0 0 48 48\" xmlns=\"http://www.w3.org/2000/svg\">\n",
              "      <circle cx=\"24\" cy=\"23\" fill=\"#FFF\" r=\"22\"/>\n",
              "      <path d=\"M33.76 34.26c2.75-2.56 4.49-6.37 4.49-11.26 0-.89-.08-1.84-.29-3H24.01v5.99h8.03c-.4 2.02-1.5 3.56-3.07 4.56v.75l3.91 2.97h.88z\" fill=\"#4285F4\"/>\n",
              "      <path d=\"M15.58 25.77A8.845 8.845 0 0 0 24 31.86c1.92 0 3.62-.46 4.97-1.31l4.79 3.71C31.14 36.7 27.65 38 24 38c-5.93 0-11.01-3.4-13.45-8.36l.17-1.01 4.06-2.85h.8z\" fill=\"#34A853\"/>\n",
              "      <path d=\"M15.59 20.21a8.864 8.864 0 0 0 0 5.58l-5.03 3.86c-.98-2-1.53-4.25-1.53-6.64 0-2.39.55-4.64 1.53-6.64l1-.22 3.81 2.98.22 1.08z\" fill=\"#FBBC05\"/>\n",
              "      <path d=\"M24 14.14c2.11 0 4.02.75 5.52 1.98l4.36-4.36C31.22 9.43 27.81 8 24 8c-5.93 0-11.01 3.4-13.45 8.36l5.03 3.85A8.86 8.86 0 0 1 24 14.14z\" fill=\"#EA4335\"/>\n",
              "    </svg>\n",
              "    <div class=\"gradient-container\"><div class=\"gradient\"></div></div>\n",
              "  </div>\n",
              "  <div class=\"carousel\">\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcR-71ru6mpc4gpy8vuvnMTkxTbdFKa8j3faKpVo5-JDZsZ5vP77tulubZLb9XPFYIwoPVi0lxXNQI1VIB4728Vor6SDpVTgFzvcoyI_XV4Fclmf0JoIzi4SxnwJJR-t-khsRV1zIoF6JFjAt7vDb_Wk5l9m2-VfPxeTglYvr3VPnLKcQArFkF6KUhM0N4OGZsVsHgYSo3AijYtqmoA=\">Alphabet financial performance</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcReU_kkKN1xoCrHouZzAdvCiMEqGQyE3w8hBExnm9AZtyj8Cjb--Ajhm9qKDVFCPzOlcHviSjHD26Oxjwx6cCF19Xz2lYCi86GP4e8rr3qxi17Z_ySzxtlHjU_57FabN-6OI94SBWPoF9e8WxhfJZejUlQhhI8xDywEXYXaCWAi8_HCDPnWznEEgiEoQpDaOTSsgAj0V06N835ZRQ==\">Alphabet company headquarters</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcS38VqBImrlUHA3ZpnsDyrwmH5lnFCsL80ahp6MycxavLqx9LpU_LOUGlyo44Iltmcu7soEBs9QkwYfYUIv7bqM4w6NHbWp5K-5JuYjfW8qO9xG243pMoN591O6cio6tlMqpgIMjvPzYC0diIvSfyhwgDmzoyJ9Wpa2-PUEdk93O4vsA4IS56FJC4QgBTaulCXUj9PCruQ=\">what is Alphabet company</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcQcggyxRwNLHNMDjO_UavX_aND9VWXm1H7f9O0yQTUmX85P8R8rxbIAyotz3F34oUbdlsHoCgy9GjepRCovpw2Z3dlw-7W1VOzpgsb1FDNnMp1fLcB0k2QVU94c8Vi7z_iPbNjUWRc6uxNU3PQMw9sF13sPlaExHVe6sUGnLs-9uIAFt9IoBUD5lcLMt18uSoqD_jSQ9AN06ysJb40=\">Alphabet company founding date</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcToBnSGGzKTSYx6VfCsa6K6jxUzvztDKktQaShAzPfMomF-e5kvNJurZSXf6ET4bE04xROQCR_z9ldbkVZXw2nu2623Tk6c1xnjouHzOqrbk1-p1JOcya1sLprjiEJEzMlw3BnpYW4n34Ol_kT7oiApKKKiOn6SP6OANDrVasUqAkTp6VBTX2rI1zxVaobdt8cyZQ==\">Alphabet recent news</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcSz9jwXP459pNRQCwaOf7INS_GmByAis8vCQ6VVCGjlBKTwdibbCp9h1L9S8x8I_SdvhcmfTiYclqsSIbgN5I6d2dNT4ITQIBdLhOvUqmCNv23t3MYNCw7Po6j_43wOJ9c-hHMoCrQUuwfxxyi5p4SXaaQblqBZVn_vkoTIMSUe7XovJLfFyV72sETwe-aIUJVrfw==\">Alphabet stock price</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcRDdy7gKzgF3aeuTV63Xq6zpbK78V5Got-eHzPYYtLr_ku6BnRsYns_s8-1xHogTgLkFGSR9saLKPgA8pDvaGlhbguWfHC-to2yyxrSKPQogKazcGAW9rowzlh-bV-E-GFXGTy4quIGVN4holwR7pfu4WtCJZGBBDl_Z5gUs1RQVqlpfqYW4fNOnv9GsFF25UknCOP81NKQsg==\">Alphabet business segments</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcQy3R-P35aHSfcS76PmdshLmomshcU76g6XlciWqoHAqI1WFCbL2JnPQrET7QXrTAey9dPpXNnnj3hEt-nsnoOUpJoKSQuvXm0vkOXqHax_XF-4i2ZUdWNDcu6I3XMShdla6qQQ8DGS3u1bcbfR34g2RHxTq8sczJVHwRLTGGqA1M4vkWcrI8-A_aMhdmgzMSAiTw==\">Alphabet competitors</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcQ7ih2X07lFdtLZJ24dIcc4EQimM7_r34KVbbCqGq74ahvn1kwasBP3q3avmXRpTPv-yr3NFHGF7ZNB2WRocNhYiigiRlGLmJ0yVwj8I4HUQFP_vUsmpGwl3Y4wF89q2C7KIO_WPnld8UXF4GGVjyp-cEi1T0H6if80QP1T8MqBtEviROpApvvXy1dxa3Ec4T5ftUtShQ==\">Alphabet key executives</a>\n",
              "  </div>\n",
              "</div>\n"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "sys_instruction = \"\"\"You are an analyst that conducts company research.\n",
        "You are given a company name, and you will work on a company report. You have access\n",
        "to Google Search to look up company news, updates and metrics to write research reports.\n",
        "\n",
        "When given a company name, identify key aspects to research, look up that information\n",
        "and then write a concise company report.\n",
        "\n",
        "Feel free to plan your work and talk about it, but when you start writing the report,\n",
        "put a line of dashes (---) to demarcate the report itself, and say nothing else after\n",
        "the report has finished.\n",
        "\"\"\"\n",
        "\n",
        "config = GenerateContentConfig(system_instruction=sys_instruction, tools=[Tool(google_search={})], temperature=0)\n",
        "response_stream = client.models.generate_content_stream(\n",
        "    model=MODEL, config=config, contents=[COMPANY])\n",
        "\n",
        "report = io.StringIO()\n",
        "for chunk in response_stream:\n",
        "  candidate = chunk.candidates[0]\n",
        "\n",
        "  for part in candidate.content.parts:\n",
        "    if part.text:\n",
        "      display(Markdown(part.text))\n",
        "\n",
        "      # Find and save the report itself.\n",
        "      if m := re.search('(^|\\n)-+\\n(.*)$', part.text, re.M):\n",
        "          # Find the starting '---' line and start saving.\n",
        "          report.write(m.group(2))\n",
        "      elif report.tell():\n",
        "        # If there's already something in the buffer, keep recording.\n",
        "        report.write(part.text)\n",
        "\n",
        "    else:\n",
        "      print(json.dumps(part.model_dump(exclude_none=True), indent=2))\n",
        "\n",
        "  # You must enable Google Search Suggestions\n",
        "  if gm := candidate.grounding_metadata:\n",
        "    if sep := gm.search_entry_point:\n",
        "      display(HTML(sep.rendered_content))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "e2gBbhEU-jCo"
      },
      "source": [
        "Very impressive! Gemini starts by planning for the task, performing relevant searches and streams out a report for you."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "P_JoMFa18Rss"
      },
      "source": [
        "### Final output\n",
        "\n",
        "Render the final output."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "1yddCUCL4yKA"
      },
      "outputs": [
        {
          "data": {
            "text/markdown": [
              "**Company Report: Alphabet Inc.**:**\n",
              "\n",
              "Alphabet Inc. is a multinational technology conglomerate holding company headquartered in Mountain View, California. It was created through a restructuring of Google on October 2, 2015, becoming the parent company of Google and several former Google subsidiaries. Alphabet is the world's second-largest technology company by revenue, after Apple, and one of the world's most valuable companies. It is considered one of the Big Five American information technology companies, alongside Amazon, Apple, Meta, and Microsoft.\n",
              "\n",
              "**Founding and Restructuring:**\n",
              "\n",
              "While Google was founded in 1998 by Larry Page and Sergey Brin, Alphabet Inc. was formed on October 2, 2015, as a restructuring to make the core Google business \"cleaner and more accountable\" while allowing greater autonomy to other ventures. In December 2019, Larry Page and Sergey Brin stepped down from their executive roles, and Sundar Pichai, who was already CEO of Google, became CEO of both Google and Alphabet. Page and Brin remain employees, board members, and controlling shareholders.\n",
              "\n",
              "**Business Segments:**\n",
              "\n",
              "Alphabet operates through three main reportable segments:\n",
              "\n",
              "*   **Google Services:** This segment includes Google's core internet products such as ads, Android, Chrome, hardware, Google Cloud, Google Maps, Google Play, Search, and YouTube. This is the most profitable segment, with revenue primarily generated from advertising on Google Search and YouTube, as well as subscriptions and smartphone sales.\n",
              "*   **Google Cloud:** This segment provides cloud services for businesses, including office software and computing platforms. Google Cloud's quarterly revenues have recently surpassed \\$10 billion, and it is showing strong growth.\n",
              "*   **Other Bets:** This segment includes various cutting-edge technology innovation ventures at different stages of development, such as Access, Calico, CapitalG, GV, Verily, Waymo, and X. This segment often posts operating losses.\n",
              "\n",
              "**Recent News and Developments:**\n",
              "\n",
              "*   Alphabet's stock recently reached an all-time high after unveiling its latest AI model, Gemini 2.0, and showcasing a new quantum computing chip called Willow.\n",
              "*   Google has launched Gemini, formerly known as Bard, an AI chatbot that supports over 40 languages.\n",
              "*   Alphabet's Q3 2024 results showed a 15% increase in consolidated revenue year-over-year, reaching \\$88.3 billion. Google Services revenue increased by 13% to \\$76.5 billion.\n",
              "*   Google Cloud's revenue exceeded \\$10 billion in a recent quarter, with over \\$1 billion in operating profit.\n",
              "*   Alphabet announced a cash dividend of \\$0.20 per share in July 2024.\n",
              "\n",
              "**Financial Performance:**\n",
              "\n",
              "*   In Q3 2024, Alphabet's consolidated revenue was \\$88.3 billion, a 15% increase year-over-year.\n",
              "*   Net income for Q3 2024 was \\$26.3 billion, compared to \\$19.7 billion a year ago.\n",
              "*   For the nine months ended September 30, 2024, sales were \\$253.5 billion, compared to \\$221.1 billion a year ago.\n",
              "*   Google Cloud's revenue has surpassed \\$10 billion in a recent quarter.\n",
              "*   Alphabet's revenue is primarily driven by Google Services, particularly advertising.\n",
              "\n",
              "**Stock Information:**\n",
              "\n",
              "*   Alphabet has two classes of stock: GOOG (Class C shares without voting rights) and GOOGL (Class A common stock).\n",
              "*   As of today, December 17, 2024, the price of GOOG is around \\$198.16, and it has increased by 4.31% in the past 24 hours.\n",
              "*   The stock reached an all-time high on December 10, 2024.\n",
              "*   Analysts' price targets for GOOG range from \\$185 to \\$240.\n",
              "\n",
              "**Key People:**\n",
              "\n",
              "*   **CEO:** Sundar Pichai\n",
              "*   **Co-Founders:** Larry Page and Sergey Brin (remain board members and controlling shareholders)\n",
              "*   **Chief Financial Officer:** Anat Ashkenazi\n",
              "*   **Other Key Executives:** Philipp Schindler (Chief Business Officer, Google), Prabhakar Raghavan (Chief Technologist, Google), Ruth M. Porat (President and Chief Investment Officer; CFO)\n",
              "\n",
              "**Competitive Landscape:**\n",
              "\n",
              "Alphabet's main competitors include:\n",
              "\n",
              "*   **Other Big Tech Companies:** Apple, Microsoft, Meta, Amazon, IBM\n",
              "*   **Software Companies:** SAP, Palantir Technologies, Shopify, AppLovin, Infosys, CrowdStrike, Atlassian, Trade Desk, NetEase, Snowflake\n",
              "*   **Other Competitors:** ByteDance, Zoom, Salesforce, Tencent, Adobe\n",
              "\n",
              "**Additional Information:**\n",
              "\n",
              "*   Alphabet's headquarters is located at 1600 Amphitheatre Parkway in Mountain View, California, also known as the Googleplex.\n",
              "*   Alphabet has a global presence with employees across six continents.\n",
              "*   Alphabet is involved in investing in infrastructure, data management, analytics, and artificial intelligence (AI).\n",
              "\n",
              "This report provides a comprehensive overview of Alphabet Inc"
            ],
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/html": [
              "<style>\n",
              ".container {\n",
              "  align-items: center;\n",
              "  border-radius: 8px;\n",
              "  display: flex;\n",
              "  font-family: Google Sans, Roboto, sans-serif;\n",
              "  font-size: 14px;\n",
              "  line-height: 20px;\n",
              "  padding: 8px 12px;\n",
              "}\n",
              ".chip {\n",
              "  display: inline-block;\n",
              "  border: solid 1px;\n",
              "  border-radius: 16px;\n",
              "  min-width: 14px;\n",
              "  padding: 5px 16px;\n",
              "  text-align: center;\n",
              "  user-select: none;\n",
              "  margin: 0 8px;\n",
              "  -webkit-tap-highlight-color: transparent;\n",
              "}\n",
              ".carousel {\n",
              "  overflow: auto;\n",
              "  scrollbar-width: none;\n",
              "  white-space: nowrap;\n",
              "  margin-right: -12px;\n",
              "}\n",
              ".headline {\n",
              "  display: flex;\n",
              "  margin-right: 4px;\n",
              "}\n",
              ".gradient-container {\n",
              "  position: relative;\n",
              "}\n",
              ".gradient {\n",
              "  position: absolute;\n",
              "  transform: translate(3px, -9px);\n",
              "  height: 36px;\n",
              "  width: 9px;\n",
              "}\n",
              "@media (prefers-color-scheme: light) {\n",
              "  .container {\n",
              "    background-color: #fafafa;\n",
              "    box-shadow: 0 0 0 1px #0000000f;\n",
              "  }\n",
              "  .headline-label {\n",
              "    color: #1f1f1f;\n",
              "  }\n",
              "  .chip {\n",
              "    background-color: #ffffff;\n",
              "    border-color: #d2d2d2;\n",
              "    color: #5e5e5e;\n",
              "    text-decoration: none;\n",
              "  }\n",
              "  .chip:hover {\n",
              "    background-color: #f2f2f2;\n",
              "  }\n",
              "  .chip:focus {\n",
              "    background-color: #f2f2f2;\n",
              "  }\n",
              "  .chip:active {\n",
              "    background-color: #d8d8d8;\n",
              "    border-color: #b6b6b6;\n",
              "  }\n",
              "  .logo-dark {\n",
              "    display: none;\n",
              "  }\n",
              "  .gradient {\n",
              "    background: linear-gradient(90deg, #fafafa 15%, #fafafa00 100%);\n",
              "  }\n",
              "}\n",
              "@media (prefers-color-scheme: dark) {\n",
              "  .container {\n",
              "    background-color: #1f1f1f;\n",
              "    box-shadow: 0 0 0 1px #ffffff26;\n",
              "  }\n",
              "  .headline-label {\n",
              "    color: #fff;\n",
              "  }\n",
              "  .chip {\n",
              "    background-color: #2c2c2c;\n",
              "    border-color: #3c4043;\n",
              "    color: #fff;\n",
              "    text-decoration: none;\n",
              "  }\n",
              "  .chip:hover {\n",
              "    background-color: #353536;\n",
              "  }\n",
              "  .chip:focus {\n",
              "    background-color: #353536;\n",
              "  }\n",
              "  .chip:active {\n",
              "    background-color: #464849;\n",
              "    border-color: #53575b;\n",
              "  }\n",
              "  .logo-light {\n",
              "    display: none;\n",
              "  }\n",
              "  .gradient {\n",
              "    background: linear-gradient(90deg, #1f1f1f 15%, #1f1f1f00 100%);\n",
              "  }\n",
              "}\n",
              "</style>\n",
              "<div class=\"container\">\n",
              "  <div class=\"headline\">\n",
              "    <svg class=\"logo-light\" width=\"18\" height=\"18\" viewBox=\"9 9 35 35\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n",
              "      <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M42.8622 27.0064C42.8622 25.7839 42.7525 24.6084 42.5487 23.4799H26.3109V30.1568H35.5897C35.1821 32.3041 33.9596 34.1222 32.1258 35.3448V39.6864H37.7213C40.9814 36.677 42.8622 32.2571 42.8622 27.0064V27.0064Z\" fill=\"#4285F4\"/>\n",
              "      <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M26.3109 43.8555C30.9659 43.8555 34.8687 42.3195 37.7213 39.6863L32.1258 35.3447C30.5898 36.3792 28.6306 37.0061 26.3109 37.0061C21.8282 37.0061 18.0195 33.9811 16.6559 29.906H10.9194V34.3573C13.7563 39.9841 19.5712 43.8555 26.3109 43.8555V43.8555Z\" fill=\"#34A853\"/>\n",
              "      <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M16.6559 29.8904C16.3111 28.8559 16.1074 27.7588 16.1074 26.6146C16.1074 25.4704 16.3111 24.3733 16.6559 23.3388V18.8875H10.9194C9.74388 21.2072 9.06992 23.8247 9.06992 26.6146C9.06992 29.4045 9.74388 32.022 10.9194 34.3417L15.3864 30.8621L16.6559 29.8904V29.8904Z\" fill=\"#FBBC05\"/>\n",
              "      <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M26.3109 16.2386C28.85 16.2386 31.107 17.1164 32.9095 18.8091L37.8466 13.8719C34.853 11.082 30.9659 9.3736 26.3109 9.3736C19.5712 9.3736 13.7563 13.245 10.9194 18.8875L16.6559 23.3388C18.0195 19.2636 21.8282 16.2386 26.3109 16.2386V16.2386Z\" fill=\"#EA4335\"/>\n",
              "    </svg>\n",
              "    <svg class=\"logo-dark\" width=\"18\" height=\"18\" viewBox=\"0 0 48 48\" xmlns=\"http://www.w3.org/2000/svg\">\n",
              "      <circle cx=\"24\" cy=\"23\" fill=\"#FFF\" r=\"22\"/>\n",
              "      <path d=\"M33.76 34.26c2.75-2.56 4.49-6.37 4.49-11.26 0-.89-.08-1.84-.29-3H24.01v5.99h8.03c-.4 2.02-1.5 3.56-3.07 4.56v.75l3.91 2.97h.88z\" fill=\"#4285F4\"/>\n",
              "      <path d=\"M15.58 25.77A8.845 8.845 0 0 0 24 31.86c1.92 0 3.62-.46 4.97-1.31l4.79 3.71C31.14 36.7 27.65 38 24 38c-5.93 0-11.01-3.4-13.45-8.36l.17-1.01 4.06-2.85h.8z\" fill=\"#34A853\"/>\n",
              "      <path d=\"M15.59 20.21a8.864 8.864 0 0 0 0 5.58l-5.03 3.86c-.98-2-1.53-4.25-1.53-6.64 0-2.39.55-4.64 1.53-6.64l1-.22 3.81 2.98.22 1.08z\" fill=\"#FBBC05\"/>\n",
              "      <path d=\"M24 14.14c2.11 0 4.02.75 5.52 1.98l4.36-4.36C31.22 9.43 27.81 8 24 8c-5.93 0-11.01 3.4-13.45 8.36l5.03 3.85A8.86 8.86 0 0 1 24 14.14z\" fill=\"#EA4335\"/>\n",
              "    </svg>\n",
              "    <div class=\"gradient-container\"><div class=\"gradient\"></div></div>\n",
              "  </div>\n",
              "  <div class=\"carousel\">\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcR-71ru6mpc4gpy8vuvnMTkxTbdFKa8j3faKpVo5-JDZsZ5vP77tulubZLb9XPFYIwoPVi0lxXNQI1VIB4728Vor6SDpVTgFzvcoyI_XV4Fclmf0JoIzi4SxnwJJR-t-khsRV1zIoF6JFjAt7vDb_Wk5l9m2-VfPxeTglYvr3VPnLKcQArFkF6KUhM0N4OGZsVsHgYSo3AijYtqmoA=\">Alphabet financial performance</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcReU_kkKN1xoCrHouZzAdvCiMEqGQyE3w8hBExnm9AZtyj8Cjb--Ajhm9qKDVFCPzOlcHviSjHD26Oxjwx6cCF19Xz2lYCi86GP4e8rr3qxi17Z_ySzxtlHjU_57FabN-6OI94SBWPoF9e8WxhfJZejUlQhhI8xDywEXYXaCWAi8_HCDPnWznEEgiEoQpDaOTSsgAj0V06N835ZRQ==\">Alphabet company headquarters</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcS38VqBImrlUHA3ZpnsDyrwmH5lnFCsL80ahp6MycxavLqx9LpU_LOUGlyo44Iltmcu7soEBs9QkwYfYUIv7bqM4w6NHbWp5K-5JuYjfW8qO9xG243pMoN591O6cio6tlMqpgIMjvPzYC0diIvSfyhwgDmzoyJ9Wpa2-PUEdk93O4vsA4IS56FJC4QgBTaulCXUj9PCruQ=\">what is Alphabet company</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcQcggyxRwNLHNMDjO_UavX_aND9VWXm1H7f9O0yQTUmX85P8R8rxbIAyotz3F34oUbdlsHoCgy9GjepRCovpw2Z3dlw-7W1VOzpgsb1FDNnMp1fLcB0k2QVU94c8Vi7z_iPbNjUWRc6uxNU3PQMw9sF13sPlaExHVe6sUGnLs-9uIAFt9IoBUD5lcLMt18uSoqD_jSQ9AN06ysJb40=\">Alphabet company founding date</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcToBnSGGzKTSYx6VfCsa6K6jxUzvztDKktQaShAzPfMomF-e5kvNJurZSXf6ET4bE04xROQCR_z9ldbkVZXw2nu2623Tk6c1xnjouHzOqrbk1-p1JOcya1sLprjiEJEzMlw3BnpYW4n34Ol_kT7oiApKKKiOn6SP6OANDrVasUqAkTp6VBTX2rI1zxVaobdt8cyZQ==\">Alphabet recent news</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcSz9jwXP459pNRQCwaOf7INS_GmByAis8vCQ6VVCGjlBKTwdibbCp9h1L9S8x8I_SdvhcmfTiYclqsSIbgN5I6d2dNT4ITQIBdLhOvUqmCNv23t3MYNCw7Po6j_43wOJ9c-hHMoCrQUuwfxxyi5p4SXaaQblqBZVn_vkoTIMSUe7XovJLfFyV72sETwe-aIUJVrfw==\">Alphabet stock price</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcRDdy7gKzgF3aeuTV63Xq6zpbK78V5Got-eHzPYYtLr_ku6BnRsYns_s8-1xHogTgLkFGSR9saLKPgA8pDvaGlhbguWfHC-to2yyxrSKPQogKazcGAW9rowzlh-bV-E-GFXGTy4quIGVN4holwR7pfu4WtCJZGBBDl_Z5gUs1RQVqlpfqYW4fNOnv9GsFF25UknCOP81NKQsg==\">Alphabet business segments</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcQy3R-P35aHSfcS76PmdshLmomshcU76g6XlciWqoHAqI1WFCbL2JnPQrET7QXrTAey9dPpXNnnj3hEt-nsnoOUpJoKSQuvXm0vkOXqHax_XF-4i2ZUdWNDcu6I3XMShdla6qQQ8DGS3u1bcbfR34g2RHxTq8sczJVHwRLTGGqA1M4vkWcrI8-A_aMhdmgzMSAiTw==\">Alphabet competitors</a>\n",
              "    <a class=\"chip\" href=\"https://vertexaisearch.cloud.google.com/grounding-api-redirect/AYygrcQ7ih2X07lFdtLZJ24dIcc4EQimM7_r34KVbbCqGq74ahvn1kwasBP3q3avmXRpTPv-yr3NFHGF7ZNB2WRocNhYiigiRlGLmJ0yVwj8I4HUQFP_vUsmpGwl3Y4wF89q2C7KIO_WPnld8UXF4GGVjyp-cEi1T0H6if80QP1T8MqBtEviROpApvvXy1dxa3Ec4T5ftUtShQ==\">Alphabet key executives</a>\n",
              "  </div>\n",
              "</div>\n"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "display(Markdown(report.getvalue().replace('$', r'\\$')))  # Escape $ signs for better MD rendering\n",
        "display(HTML(sep.rendered_content))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "leOZmicAwTSn"
      },
      "source": [
        "As you can see, the Gemini model is able to write a concise, accurate and well-structured research report for us. All the information in the report is factual and up-to-date.\n",
        "\n",
        "Note that this tutorial is meant to showcase the capability of the new search tool and inspire interesting use cases, not to build a production research report generator. If you are looking to use a tool, please check out Google [Deep Research](https://blog.google/products/gemini/google-gemini-deep-research/) in the Gemini app."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4677dd58e9b5"
      },
      "source": [
        "## Next Steps\n",
        "\n",
        "* To learn more about the search tool, check out the [Search tool documentation](https://ai.google.dev/gemini-api/docs/models/gemini-v2#search-tool).\n",
        "* To get started with streaming, check out the [Streaming Quickstart](../quickstarts/Streaming.ipynb).\n",
        "* To get started with the search tool, check out the [Search tool quick start](../quickstarts/Search_Grounding.ipynb).\n",
        "* To see how much easier and more powerful the search tool in Gemini 2.0 is than the previous search grounding feature, compare this tutorial with the [previous example](../examples/Search_grounding_for_research_report.ipynb).\n",
        "\n",
        "To learn more about all the Gemini features, check out the [Gemini quickstart notebooks](https://github.com/google-gemini/cookbook/tree/main/quickstarts/)."
      ]
    }
  ],
  "metadata": {
    "colab": {
      "collapsed_sections": [
        "lb5yiH5h8x3h"
      ],
      "name": "Search_grounding_for_research_report.ipynb",
      "toc_visible": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
